var e = require;
var t = module;
var n = exports;
Object.defineProperty(n, "__esModule", {
    value: !0
});
var o = e("NativeAdBase"),
i = cc._decorator,
a = i.ccclass,
r = i.property,
s = function(e) {
    __extends(t, e);
    function t() {
        var t = null !== e && e.apply(this, arguments) || this;
        t.autoShow = !0;
        t.autoFresh = !0;
        t.needProtect = !1;
        t.autoClick = !1;
        t.delay = 0;
        t.adNode = null;
        t.title = null;
        t.desc = null;
        t.iconSprite = null;
        t.mainSprite = null;
        t.nativeItem = null;
        t.closeBtn = null;
        t.extentBtns = [];
        t.showState = 0;
        return t
    }
    t.prototype.onEnable = function() {
        var e = this;
        if (cc.sys.platform == cc.sys.OPPO_GAME) {
            SDK.Base.Event.on("onFreshNativeAdData", this.onFresh, this);
            SDK.Base.Event.on("onGetNativeAd", this.onGetAD, this);
            if (this.autoShow) {
                this.unscheduleAllCallbacks();
                this.scheduleOnce(function() {
                    e.show()
                },
                this.delay);
                this.autoFresh && this.schedule(function() {
                    e.show()
                },
                SDK.Mgr.Inst.nativeFreshTime + 1, cc.macro.REPEAT_FOREVER, this.delay)
            }
        }
    };
    t.prototype.onDisable = function() {
        if (cc.sys.platform == cc.sys.OPPO_GAME) {
            SDK.Base.Event.off("onFreshNativeAdData", this.onFresh, this);
            SDK.Base.Event.off("onGetNativeAd", this.onGetAD, this)
        }
    };
    t.prototype.start = function() {};
    t.prototype.onFresh = function(e) {
        this.nativeItem && e == this.nativeItem.adId && this.show()
    };
    t.prototype.onGetAD = function() {
        1 == this.showState && this.show()
    };
    t.prototype.canShow = function() {
        return this.needProtect ? SDK.Mgr.Inst.getAds().hasNative() && SDK.Mgr.Inst.isAdOpen: SDK.Mgr.Inst.getAds().hasNative()
    };
    t.prototype.show = function() {
        var e = this;
        this.showState = 1;
        if (this.canShow()) {
            if (this.autoClick) {
                if (!SDK.Mgr.Inst.customData || "true" != SDK.Mgr.Inst.customData.nativeAutoJump) {
                    this.node.destroy();
                    return
                }
                this.scheduleOnce(function() {
                    e.click();
                    e.node.destroy()
                },
                .5)
            }
            this.showState = 2;
            var t = SDK.Mgr.Inst.getAds().getNative();
            this.nativeItem = t;
            this.nativeItem.show();
            this.adNode && (this.adNode.active = !0);
            this.closeBtn && (this.closeBtn.active = !0);
            this.extentBtns.forEach(function(e) {
                e.active = !0
            });
            this.title && (this.title.string = this.nativeItem.title);
            this.desc && (this.desc.string = this.nativeItem.desc);
            this.iconSprite && (this.nativeItem.iconUrl ? SDK.Util.Helper.loadImage(this.iconSprite, this.nativeItem.iconUrl) : this.nativeItem.imgUrl && SDK.Util.Helper.loadImage(this.iconSprite, this.nativeItem.imgUrl));
            this.mainSprite && (this.nativeItem.imgUrl ? SDK.Util.Helper.loadImage(this.mainSprite, this.nativeItem.imgUrl) : this.nativeItem.iconUrl && SDK.Util.Helper.loadImage(this.mainSprite, this.nativeItem.iconUrl))
        } else {
            var n = this,
            o = function() {
                if (n.canShow()) {
                    n.unschedule(o);
                    n.show()
                }
            };
            this.schedule(o, .2, 25)
        }
    };
    t.prototype.click = function() {
        if (this.nativeItem) {
            SDK.Mgr.Inst.customData && "false" == SDK.Mgr.Inst.customData.nativeNotFresh && this.close();
            SDK.Mgr.Inst.getAds().clickNative();
            this.nativeItem.click()
        }
    };
    t.prototype.close = function() {
        this.adNode && (this.adNode.active = !1);
        this.closeBtn && (this.closeBtn.active = !1);
        this.extentBtns.forEach(function(e) {
            e.active = !1
        })
    };
    __decorate([r(cc.Boolean)], t.prototype, "autoShow", void 0);
    __decorate([r(cc.Boolean)], t.prototype, "autoFresh", void 0);
    __decorate([r(cc.Boolean)], t.prototype, "needProtect", void 0);
    __decorate([r(cc.Boolean)], t.prototype, "autoClick", void 0);
    __decorate([r(cc.Float)], t.prototype, "delay", void 0);
    __decorate([r(cc.Node)], t.prototype, "adNode", void 0);
    __decorate([r(cc.Label)], t.prototype, "title", void 0);
    __decorate([r(cc.Label)], t.prototype, "desc", void 0);
    __decorate([r(cc.Sprite)], t.prototype, "iconSprite", void 0);
    __decorate([r(cc.Sprite)], t.prototype, "mainSprite", void 0);
    __decorate([r(cc.Node)], t.prototype, "closeBtn", void 0);
    __decorate([r([cc.Node])], t.prototype, "extentBtns", void 0);
    return __decorate([a], t)
} (o.default);
n.default = s